﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Data;
using Database;

namespace Business
{
   public class QuanLyLopHoc
    {
         TrungTamEntities trungtam;
         public QuanLyLopHoc()
        {
            trungtam = new TrungTamEntities();
        }
        public List<LopHoc> LayDanhSachLopHoc()
        {
            var list= (from p in trungtam.LopHocs
                       select p).ToList();
            return list;
        }

      
    
        public LopHoc LayLopHocTheoMa(String MaLop)
        {
            var lop = (from p in trungtam.LopHocs
                           where p.MaLop.Equals(MaLop)
                           select p).First();
            return lop;
        }
        public bool ThemLopHoc(LopHoc lophoc)
        {
            try
            {
                trungtam.AddToLopHocs(lophoc);
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool XoaLopHoc(String MaLop)
        {
            var lop = (from p in trungtam.LopHocs
                           where p.MaLop.Equals(MaLop)
                           select p).First();
            try
            {
                trungtam.DeleteObject(lop);
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SuaLopHoc(LopHoc lophoc)
        {
            var lop = (from p in trungtam.LopHocs
                           where p.MaLop.Equals(lophoc.MaLop)
                           select p).First();
            lop.MoTa = lophoc.MoTa;
            lop.GiaoVienPT = lophoc.GiaoVienPT;
            lop.PhongHoc=lophoc.PhongHoc;
            lop.HocPhi = lophoc.HocPhi;
            lop.LichHoc = lophoc.LichHoc;           
            lop.NgayKhaiGiang = lophoc.NgayKhaiGiang;
            lop.SiSo = lophoc.SiSo;
            try
            {
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
